<?php

/*
 * CONTROLE FINANÇAS PESSOAIS
 *
 * Página: logar (helpers/php)
 *
 * Histórico:
 *		v. 11/11/2012, EDGARD FANTINI JÚNIOR - efantinij@gmail.com
 *			- versão inicial
 *
 * FRAMWORK: edframe - Copyleft (cc) 2012 EDMAR Sistemas
 */

$segura = 'USC.CO.10.00' ;
$descricao = '';

function valLogar($nome, $senha)
{
	try
	{
		TTransaction::open($_SESSION['infoCon']);
		$_var[0] = 'sucesso' ;
		$_var[1] = 'login efetuado' ;

		$a = new suser ;
		$a->nometela = $nome ;
		$a->senha = md5($senha) ;
		$a->ativo = 'A' ;
		$a->colunas = "use, nometela" ;
		$_User = $a->suser ;

		if (empty($_User))
			throw new Exception("usuario n&atilde;o encontrado(a).") ;

		$_SESSION['userId'] = $_User[0]->use ;
		$_SESSION['nomeTela'] = $_User[0]->nometela ;
		TTransaction::rollback() ;
	}
	catch (Exception $e) // em caso de exceção
	{
		$_var = MformTryCache::objReturn($e) ;
		TTransaction::rollback() ;
	}
	return $_var ;
}

function menu()
{
	try
	{
		TTransaction::open($_SESSION['infoCon']);
		TTransaction::setLogger(new TLoggerTXT('/tmp/logar_menu.txt'));
		$_var[0] = 'sucesso' ;
		$_var[1] = 'menu montado' ;
		$menu = "<P>MENU PRINCIPAL</P><DIV id='masterdiv'>" ;

		// MENU COMPLEXO verifica o menu da sfuncao

		$uf = new suserfun ;
		$uf->usuario = $_SESSION['userId'] ;
		$uf->ativo = 'A' ;
		$uf->colunas = "func" ;
		$_UserFun = $uf->suserfun ;

		foreach($_UserFun as $userFun)
			$_FuncoesDoUser .= $userFun->func."," ;


		$me = new sitensaux ;
		$me->tabaux = 1 ;
		$me->ativo = 'A' ;
		$me->colunas = 'item, nome, des' ;
		$me->order = 'ordem' ;
		$_Menu = $me->sitensaux ;

		$m = 0 ;
		foreach($_Menu as $men)
		{
			$menu .= "<DIV class='menutitle' onclick='SwitchMenu(&quot;sub" .$m ."&quot;)' >" ;
			$menu .= $men->nome ;
      $menu .= "</DIV>" ;
      $menu .= "<SPAN class='submenu' id='sub". $m ."' >" ;

			$a = new sfuncao ;
			$a->func = rtrim($_FuncoesDoUser,",")."#IN#TA" ;
			$a->menu = $men->item ;
			$a->ativo = 'A' ;
			$a->order = 'nometela' ;
			$a->colunas = 'func, programa, nometela' ;
			$_Funcao = $a->sfuncao ;


			foreach ($_Funcao as $funcao)
			{
				TTransaction::log('linha 96 programa = '.$funcao->programa);
				$menu .= "<BUTTON  onclick='envio(&quot;". $funcao->programa ."&quot;)' >" ;
				$menu .= $funcao->nometela ;
				$menu .= "</BUTTON><BR>" ;
			}
			$m++;
      $menu .= "</SPAN>" ;
		}
		$menu .= "</DIV>" ;
		$_SESSION['menu'] = $menu ;

	}
	catch (Exception $e) // em caso de exceção
	{
		$_var = MformTryCache::objReturn($e) ;
		TTransaction::rollback() ;
	}
	return $_var ;
}

sajax_export("valLogar", "menu") ;
sajax_handle_client_request() ;

try
{
	$a = new Vlogar ;
	$a->editIndex ;
	$caixaGeral = $a->form[0] ;

	$_Botoes = new MGeraBotoes ;
	$caixaBotoes = $_Botoes->gerar("BUSCAR|valLogon|G") ;
	TTransaction::close() ;
}
catch (Exception $e)
{
	$_var = MformTryCache::objReturn($e) ;
	TTransaction::rollback() ;
	return $_var ;
}
